﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;


namespace WebSys.UI.Control.ZhengShou
{
    public class RC_FWEditControl : MPBasicTemplate
    {
        TextBox txt接收人员, txt发送人员, txt主题, txt接收人员Id, txt内容;
        Button btnXz, Button2, Button1, btnUpload;
        DropDownList dlldepartment, dllperson;
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        MPPersistence Persistence1;
        Panel panel1;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] != null)
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            InitControl();

            Persistence1.Table = "Zs_Gw";
            Persistence1.Key = "ID";
            Persistence1.KeyValue = HttpContext.Current.Request["id"];
            Persistence1.ConnStr = _EluZSDataProvider.GetConnectionString();
            Persistence1.BindControl = panel1;
            if (string.IsNullOrEmpty(Persistence1.KeyValue))
            {
                btnUpload.Visible = false;
            }
            if (!Page.IsPostBack)
            {
                BindDll();
                Bind();   
            }
            
        }

        protected void BindDll()
        {
            string sql = "select * from zs_role";
            DataTable dt =  _EluZSDataProvider.GetTable(sql);
            dlldepartment.DataSource = dt;
            dlldepartment.DataTextField = "rolename";
            dlldepartment.DataValueField = "id";
            dlldepartment.DataBind();
        }

        

        protected void InitControl()
        {
            Persistence1 = (MPPersistence)FindControl("Persistence1");
            panel1 = (Panel)FindControl("panel1");
            txt接收人员Id = (TextBox)FindControl("txt接收人员Id");
            txt接收人员 = (TextBox)FindControl("txt接收人员");
            txt主题 = (TextBox)FindControl("txt主题");
            txt内容 = (TextBox)FindControl("txt内容");
            Button1 = (Button)FindControl("Button1");
            Button1.Click += new EventHandler(Button1_Click);
            Button2 = (Button)FindControl("Button2");
            Button2.Click += new EventHandler(btnSeach_Click);
            dlldepartment = (DropDownList)FindControl("dlldepartment");
            dlldepartment.SelectedIndexChanged += new EventHandler(dlldepartment_SelectedIndexChanged);
            dllperson = (DropDownList)FindControl("dllperson");
            btnXz = (Button)FindControl("btnXz");
            btnXz.Click += new EventHandler(btnXz_Click);
            btnUpload = (Button)FindControl("btnUpload");
            btnUpload.Click += new EventHandler(btnUpload_Click);
            txt发送人员 = (TextBox)FindControl("txt发送人员");
        }

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            //设置文件上传的关键字段
            if (!string.IsNullOrEmpty(Persistence1.KeyValue))
            {
                if (true)
                {

                }
                string strScript = string.Format("<script>OpenFileUpload('{0}','{1}','{2}');</script>",
                    Persistence1.KeyValue, base.Page.Request["ID"].Trim(), base.Page.Request["ID"].Trim());
                Page.ClientScript.RegisterStartupScript(this.GetType(), "opennew", strScript);
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string sql = "Select name from zs_user where id = '" + userid + "'";
            DataTable dt = _EluZSDataProvider.GetTable(sql);

            txt发送人员.Text = dt.Rows[0]["name"].ToString();
            Persistence1.Update();
            Page.Response.Redirect("RC_FWEdit.aspx?id=" + Persistence1.KeyValue+ "");
        }

        protected void btnXz_Click(object sender, EventArgs e)
        {
            txt接收人员Id.Text += dllperson.SelectedValue + ",";
            txt接收人员.Text += dllperson.Items[dllperson.SelectedIndex].Text + ",";
        }

        protected void dlldepartment_SelectedIndexChanged(object sender, EventArgs e)
        {
            String sql = "Select * from zs_user where id in (Select userid from  zs_user_in_role where roleid = '" + dlldepartment.SelectedValue + "')";
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            dllperson.DataSource = dt;
            dllperson.DataTextField = "name";
            dllperson.DataValueField = "id";
            dllperson.DataBind();
        }

        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
            Bind();
        }

        protected void btnSeach_Click(object sender, EventArgs e)
        {
            Page.Response.Redirect("RC_FW.aspx");
        }

        protected void Bind()
        {

          
        }

    }
}
